--洗血
local xixue = fk.CreateSkill {
    name = "mcdh_xixue",
    tags = {Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

xixue:addEffect(fk.Damaged,{
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local all_choices = {"xixue1","xixue2", "xixue-offense"}
        local choices = {"xixue1","xixue2", "xixue-offense"}
        if player.faceup and not player.chained then
            table.removeOne(choices,"xixue2")
        end
        if player:isKongcheng() then
            table.removeOne(choices,"xixue-offense")
        end
        local choice = room:askForChoice(player, choices, self.name, nil, nil,all_choices)
        if choice == "xixue1" or choice == "xixue-offense" then
            room:setPlayerMark(room.current,"@@xixue-turn",1)
        end
        if choice == "xixue2" or choice == "xixue-offense" then
            player:reset()
        end
        if choice == "xixue-offense" then
            room:recastCard(player:getCardIds("h"), player, self.name)
        end
    end,
})

xixue:addEffect(fk.CardUsing,{
    can_refresh = function(self, event, target, player, data)
        return target == player and target:getMark("@@xixue-turn") ~= 0 and (data.card:isCommonTrick() or data.card.type == Card.TypeBasic)
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player,"@@xixue-turn",0)
        if data.toCard ~= nil then
            data.toCard = nil
        else
            data.nullifiedTargets = table.map(player.room.players, Util.IdMapper)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_xixue"] = "洗血",
    [":mcdh_xixue"] = "锁定技, 当你受到伤害后，你选择一项:\n1. 令当前回合角色本回合使用的下一张基本牌或普通锦囊牌无效；\n2. 复原你的武将牌；\n背水：重铸所有手牌。",
    ["xixue1"] = "1. 令当前回合角色本回合使用的下一张基本牌或普通锦囊牌无效",
    ["xixue2"] = "2. 复原武将牌",
    ["xixue-offense"] = "背水：重铸所有手牌。",
    ["@@xixue-turn"] = "洗血",
}

return xixue